from django.db import models
from apps.common.base.models import BaseModel
from apps.user.models import UserModel

class Coupon(BaseModel):

    status = (
        ('wait_use', "待使用"),
        ('has_use', "已使用"),
        ('due', "已过期"),
    )
    types = (
        ('1', "兑换券"),
        ('2', "立减券"),
        ('3', "折扣券"),
        ('4', "满减券"),
    )
    cancelType = (
        ('1', "扫码核销"),
        ('2', "输码核销"),
        ('3', "下单核销"),
    )
    weeks = (
        ('1', "周一至周日"),
        ('2', "周一至周五"),
        ('3', "周六至周日"),
    )
    times = (
        ('1', "全天"),
        ('2', "上午"),
        ('3', "下午"),
    )

    user = models.ForeignKey(UserModel, related_name="user_coupon", verbose_name='用户',
                             on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)
    types = models.CharField("类型", max_length=200, choices=types, blank=True, null=True, default='')
    name = models.CharField("名称", max_length=200, blank=True, null=True, default='')
    code = models.CharField("唯一码", max_length=200, blank=True, null=True, default='')
    content = models.CharField("优惠内容", max_length=200, blank=True, null=True, default='')
    money = models.DecimalField("金额", max_digits=10, decimal_places=2, default=0)
    fullMoney = models.DecimalField("消费总金额", max_digits=10, decimal_places=2, default=0)
    startTime = models.DateTimeField('有效日期', null=True, blank=True)
    endTime = models.DateTimeField('截止日期', null=True, blank=True)
    weeks = models.CharField("周几可用", max_length=200, choices=weeks, default='1')
    times = models.CharField("可用时间段", max_length=200, choices=times, default='1')
    status = models.CharField("状态", max_length=200, choices=status, default='wait_use')
    remark = models.CharField("备注", max_length=200, blank=True, null=True, default='')
    cancelType = models.CharField("核销方式", max_length=200, choices=cancelType, blank=True, null=True, default='')
    cancelTime = models.DateTimeField('核销日期', null=True, blank=True)

    class Meta:
        verbose_name = 'Coupon'
        verbose_name_plural = verbose_name
